package com.guge.sports.controller;


import com.guge.sports.entity.Dto.Option;
import com.guge.sports.entity.Dto.StTeacherDto;
import com.guge.sports.entity.StTeacher;
import com.guge.sports.service.StDeptService;
import com.guge.sports.service.StTeacherService;
import com.guge.sports.toolPackage.base.BaseController;
import com.guge.sports.toolPackage.utils.MyPager;
import com.guge.sports.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-09-14
 */
@Api(description = "教师接口")
@RestController
//@Controller
@RequestMapping("/sports/st-teacher")
public class StTeacherController extends BaseController<StTeacher> {

    @Autowired
    private StTeacherService stTeacherService;

    @Autowired
    private StDeptService stDeptService;

    // 老师搜索条件渲染
    @ApiOperation(value = "教师搜索条件渲染")
    @GetMapping("/getSearchCondition")
    @ResponseBody
    public R getDeptNameAndDidList(){
        List<Option> depts = stDeptService.getDeptNameAndDidList();
        List<Option> goStateTimes = stTeacherService.getGoStateTimeList();
        return R.ok().data("depts",depts).data("goStateTimes",goStateTimes);
    }

    //分页查询
    @ApiOperation(value = "实际分页查询")
    @PostMapping("/selectStTeacherPage")
    public Object selectStTeacherPage(MyPager<StTeacherDto> myPager, @RequestBody(required = false) StTeacherDto entity) {
        return R.ok().data("page",stTeacherService.selectStTeacherPage(myPager,entity));
    }


    //导出表格
    @ApiOperation(value = "导出表格")
    @GetMapping("/excelExport")
    public void excelExport(HttpServletResponse httpServletResponse) {
       stTeacherService.excelExport(httpServletResponse);
    }


    //导出表格
    @ApiOperation(value = "导入表格")
    @PostMapping("/excelImport")
    public R excelImport( MultipartFile uploadFile) {
        return R.result(stTeacherService.excelImport(uploadFile));
    }


    //导出表格
    @ApiOperation(value = "下载表格")
    @GetMapping ("/excelDownload")
    public R excelDownload(HttpServletResponse response) {
        return R.result(stTeacherService.excelDownload(response));
    }


}

